#include <iostream>
#include <algorithm>
using namespace std;
constexpr int MAXV = 100, INF = 1 << 30;
int V;
int cost[MAXV][MAXV];
int mincost[MAXV];
bool used[MAXV];

int prim() {
    fill(used, used + V, false);
    fill(mincost, mincost + V, INF);
    mincost[0] = 0;
    int res = 0;

    while (true) {
        int v = -1;
        for (int u = 0; u < V; u++)
            if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; // 首先找到目前距离最短的点
        if (v == -1) break;
        used[v] = true;
        for (int u = 0; u < V; u++) {
            mincost[u] = min(mincost[v] + cost[v][u], mincost[u]); // 更新最小的边
        }
        res += mincost[v];
    }
    return res;
}